package com.tvein.sanguo.room.controller
{
	//flash
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.room.model.SystemProxy;
	import com.tvein.sanguo.room.view.RoomMediator;
//
	public class RoomFile extends SimpleFabricationCommand implements ICommand
	{
		private var systemData:SystemProxy;
		private var roomMediator:RoomMediator;
		
		override public function execute(notification:INotification) : void
		{
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			roomMediator = facade.retrieveMediator(RoomMediator.NAME) as RoomMediator;
			
			systemData.srcListAdd(String(notification.getBody()));
			
			for (var i:int = 0; i < systemData.roomList.length; i++)
			{
				if (systemData.roomList[i][2] == notification.getBody())
				{
					systemData.roomList[i][3] = true;
				}
				
				if (systemData.roomList[i][4] == notification.getBody())
				{
					systemData.roomList[i][5] = true;
				}
				
				if (systemData.roomList[i][3] && systemData.roomList[i][5])
				{
					roomMediator.roomShell.console("setButtonVisible", {"buttonName":systemData.roomList[i][1], "isVisible":true});
					
					systemData.roomList.splice(i, 1);
					i --;
				}
			}
		}
	}
}